import six


def to_text(value, encoding='utf-8'):
    """Convert value to unicode, default encoding is utf-8
    :param value: Value to be converted
    :param encoding: Desired encoding
    """
    if not value:
        return ''
    if isinstance(value, six.text_type):
        return value
    if isinstance(value, six.binary_type):
        return value.decode(encoding)
    return six.text_type(value)


"""
# 需要按实际行驶进行修改
def get_cache_value(key, from_db=True, content_type='json'):
    value = redis_conn.get(key)
    if from_db and not value:
        common_config = CommonConfigs.query.filter(CommonConfigs.key == key).first()
        content = common_config.content

        # 重新将key value 存入 redis中
        redis_conn.set(key, content, ttl=RedisConst.REDIS_TTL)
        value = redis_conn.get(key)
    return parser_cache_value(content=value, content_type=content_type)
"""
